<!-- 子组件，负责要求和花钱 -->

<template>
    <div>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;子组件
        <div>
            子组件的生活费: {{ props.money }}
            <br>
            <button @click="getMoney">要生活费!</button>
            <br>
            子组件的零花钱: {{ linghuaqian }}
            <br>
            <button @click="getLinghua">要零花钱!</button>
        </div>
    </div>
</template>

<script setup>
import { inject } from 'vue'
// 定义接受的参数,生活费
const props = defineProps({
    money: {
        type: Number,
        required: true
    }
})
// 定义响应事件,准备向父组件要钱
const emit = defineEmits(['daqian'])
const getMoney = () => {
    emit('daqian', 500);
}

// 爷爷相关的零花钱
const linghuaqian = inject('linghuaqian')// 爷爷给的零花钱
const getLinghuaqian = inject('sendLinhuaqian')// 爷爷给的卡,密码是sendLinhuaqian
const getLinghua = () => {
    console.log(getLinghuaqian)
    getLinghuaqian(300) // 要300的零花钱
}
</script>

<style scoped></style>